package com.isoft.c2team3service2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.c2team3service2.entity.ArtistPrivatePost;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArtistPrivatePostMapper extends BaseMapper<ArtistPrivatePost> {
    /**
     * 查询用户向指定艺人发送的私密帖子（用户视角）
     */
    @Select("SELECT * FROM artist_private_post WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<ArtistPrivatePost> selectByUserAndArtist(Integer userId);

    /**
     * 查询艺人收到的所有私密帖子（艺人视角）
     */
    @Select("SELECT * FROM artist_private_post WHERE artist_id = #{artistId} ORDER BY create_time DESC")
    List<ArtistPrivatePost> selectByArtistId(Integer artistId);
    /**
     * 校验帖子权限：仅用户本人或艺人可查询
     */
    @Select("SELECT COUNT(*) FROM artist_private_post WHERE id = #{postId} AND (user_id = #{userId} OR artist_id = #{userId})")
    int checkPermission(Integer postId, Integer userId);
}